import { request, go_to, showToast,checkLogin } from '../../../utils/util.js';
import { JsList } from '../../../config/api.js';
const app = getApp();
var random = Math.random();
Page({
  data: {
    navH:0,
    opcitys: 0,
    userInfo:[],
    articleList:[]
  },

  onLoad: function (options) {
    var that= this;

    let navH = app.globalData.navHeight;
    /*顶部导航高度*/
    that.setData({
      navH: navH
    });
  },

  onShow: function () {
    /*判断是否登录*/
    let userInfo = checkLogin();
    this.setData({
        userInfo: userInfo
    });
    this.getList();
  },

  getList(){
    let _this = this;
    request(JsList, 'GET').then(function (res) {
      if (res.s == 1) {
        _this.setData({
          articleList:res.d.rows,
          hidden: true
        });
      }else{
        if (res.s == 100) {
          // 去登录
          go_to('navigateTo','pages/login/login');
        }else{
          _this.setData({
            hidden: false
          })          
          showToast(res.m, 2);
        }
      }
    })
  },

  goto(e){
    let id = e.currentTarget.dataset.id;
    go_to('navigateTo','pages/index/view/view','id='+id);
  },

  goto_add(){
    go_to('navigateTo','pages/index/add/add');
  }

})